// (c) Copyright 2013 Mike Riedel.
// This source is subject to the Microsoft Public License (Ms-PL).
// All other rights reserved.

using System;

namespace FreshMeat.ErrorHandlingBlock
{
   /// <summary>
   /// Describes the result of the error policy that processed an error.
   /// </summary>
   public struct ErrorPolicyResult
   {
      /// <summary>
      /// The diagnosis, which will either be the original error or an
      /// error that has been substituted for the original error.
      /// </summary>
      public readonly Exception Diagnosis;

      /// <summary>
      /// Whether the action should be retried.
      /// </summary>
      public readonly bool ShouldRetry;

      /// <summary>
      /// How long to wait until retrying the action.
      /// </summary>
      public readonly TimeSpan TimeUntilRetry;

      /// <summary>
      /// Creates instance that should not be retried.
      /// </summary>
      /// <param name="diagnosis"></param>
      public ErrorPolicyResult(Exception diagnosis)
      {
         Diagnosis = diagnosis;
         ShouldRetry = false;
         TimeUntilRetry = TimeSpan.Zero;
      }

      /// <summary>
      /// Creates instance that should be retried.
      /// </summary>
      public ErrorPolicyResult(Exception diagnosis, TimeSpan timeUntilRetry)
      {
         Diagnosis = diagnosis;
         ShouldRetry = true;
         TimeUntilRetry = timeUntilRetry;
      }
   }
}